function fileLoaderEnvironment() {
	
	// Default
	this.jsPrefix = "public/scripts/";
	this.cssPrefix = "public/styles/";
	/**
	* @private
	*/
	this.jsSuffix = "";
	this.cssSuffix = "";
	this.setPrefix = function (k, type) {
		if (type == "js") {
			this.jsPrefix = k;
		} else {
			this.cssPrefix = k;
		}
	};
	this.setSuffix = function (k, type) {
		if (type == "js") {
			this.jsSuffix = k;
		} else {
			this.cssSuffix = k;
		}
	};
	this.loadJs = function (fileName, domID) {
		if (fileName != null && fileName != "") {
			if (typeof fileName == "string") {
				var _jsfile = fileName.split("|");
				var _jsfilelength = _jsfile.length;
				if (_jsfilelength == 1) {
					if (domID == "" || domID == null) {
						var _jsName = fileName.split("/");						
						domID = _jsName[_jsName.length-1];
					}
					var _loadjs = this.loadJsFile(_jsfile, domID);
				} else {
					var _loadjs = this.loadJsArray(_jsfile);
				}
			} else {
				var _loadjs = this.loadJsArray(fileName);
			}
			return _loadjs;
		}
		return 1;
	};
	
	this.loadGoogleMap = function(key){
		var head = document.getElementsByTagName("head").item(0);
		old = document.getElementById("googleMap");
		if (old) {
			return 1;
		}
		
		_fileName = "http://maps.google.com/maps?file=api&amp;v=2&amp;key="+key;
		script = document.createElement("script");
		script.src = _fileName;
		script.type = "text/javascript";
		script.defer = false;
		script.charset = 'utf-8';
		script.language = "javascript";
		script.id = "googleMap";
		void (head.appendChild(script));
		return 1;
	}
	
	this.loadJsFile = function (fileName, domID) {
		if (fileName != null && fileName != "") {
			var head = document.getElementsByTagName("head").item(0);
			if (domID == "" || domID == null) {				
				domID = fileName;
				old = document.getElementById(domID);
				if (old) {
					return 1;
				}
			} else {
				old = document.getElementById(domID);
				if (old) {
					head.removeChild(old);
				}
			}
			_fileName = this.jsPrefix + fileName + this.jsSuffix;
			script = document.createElement("script");
			script.src = _fileName;
			script.type = "text/javascript";
			script.defer = false;
			//script.charset = 'utf-8';
			script.language = "javascript";
			script.id = domID;
			void (head.appendChild(script));
		}
		return 1;
	};
	this.loadJsArray = function (fileNames) {
		var length = fileNames.length;
		var _loadjsArray = new Array();
		for (i = 0; i < length; i++) {
			_loadjsArray[i] = this.loadJsFile(fileNames[i], "");
		}
		for (i = 0; i < length; i++) {
			if (_loadjsArray[i] != 1) {
				return 0;
			}
		}
		return 1;
	};
	this.loadCss = function (fileName, domID) {
		if (fileName != null && fileName != "") {
			fileName = this.cssPrefix + fileName + this.cssSuffix;
			var cssTag = document.getElementById(domID);
			var head = document.getElementsByTagName("head").item(0);
			if (cssTag) {
				head.removeChild(cssTag);
			}
			css = document.createElement("link");
			css.href = fileName;
			css.rel = "stylesheet";
			css.type = "text/css";
			css.id = domID;
			head.appendChild(css);
		}
		return 1;
	};
	this.autoLoad = function (domId, jsFile, cssFile) {
		if(domId == null || domId == ""){
			return 1;
		}
		var target = document.getElementById(domId);
		if (target != null) {
			if (jsFile != null && jsFile != "") {
				var loadJs = this.loadJs(jsFile);
			} else {
				var loadJs = 1;
			}
			if (cssFile != null && cssFile != "") {
				var loadCss = this.loadCss(cssFile, "css");
			} else {
				var loadCss = 1;
			}
			if (loadJs == 1 && loadCss == 1) {
				return 1;
			} else {
				return 0;
			}
		}
		return 1;
	};
}
FileLoader = new fileLoaderEnvironment();

